package cn.t.web.order;

import cn.t.core.mode.PageInfoDTO;
import cn.t.core.mode.PageQueryDTO;
import cn.t.facade.order.ReconFacade;
import cn.t.listener.ReconciliationImportInfoListener;
import cn.t.request.ReconciliationReq;
import cn.t.vo.order.ReconciliationVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 对账管理
 *
 * @author t
 * @since 2024-05-24 10:15:14
 */
@Slf4j
@RestController
@RequestMapping("recon")

@AllArgsConstructor
public class ReconController {
    private final ReconFacade reconFacade;

    /**
     *对账分页列表
     */
    @PostMapping("/page")
    public PageInfoDTO<ReconciliationVO> page(@RequestBody PageQueryDTO<ReconciliationReq> req){
        return this.reconFacade.page(req);
    }

    /**
     * 创建对账单
     */
    @PostMapping("/importReconciliation")
    public void importReconciliation(@RequestParam(required = false) MultipartFile file, @RequestParam Long firmId, @RequestParam String startDate, @RequestParam String endDate) {
        this.reconFacade.importReconciliation(file, firmId, startDate, endDate, new ReconciliationImportInfoListener());
    }

    /**
     * 删除对账单
     */
    @PostMapping("/remove/{id}")
    public Boolean remove(@PathVariable Long id){
        return this.reconFacade.remove(id);
    }

    /**
     * 推送对账信息给客户
     */
    @PostMapping("/pushToCustomer/{id}")
    public Boolean pushToCustomer(@PathVariable Long id) {
        return this.reconFacade.pushToCustomer(id);
    }



    /**
     * 查询基础信息
     */
    @GetMapping("/{id}")
    public ReconciliationVO getBaseInfo(@PathVariable Long id){
        return  this.reconFacade.getBaseInfo(id);
    }
}

